#include "rclcpp/rclcpp.hpp"
#include "rclcpp/timer.hpp"
#include <chrono>

using namespace std::chrono_literals;
//目的：加插定时器之间会不会相互阻塞
class MultiTimerNode : public rclcpp::Node {
public:
  MultiTimerNode(std::string name) : Node(name) {
    RCLCPP_INFO(this->get_logger(), "Start up node : %s", name.c_str());
    timer1_ = this->create_wall_timer(
        1s, std::bind(&MultiTimerNode::timer1_callback, this));
    timer2_ = this->create_wall_timer(
        3s, std::bind(&MultiTimerNode::timer2_callback, this));
  }
  void timer1_callback() {
    // RCLCPP_INFO(this->get_logger(), "timer1 thread pid is %d", gettid());
    // RCLCPP_INFO(this->get_logger(), "timer1 sleep for 5s...");
    // rclcpp::sleep_for(3s);
    RCLCPP_INFO(this->get_logger(), "Timer 1 callback");
  }
  void timer2_callback() {
    // RCLCPP_INFO(this->get_logger(), "timer2 thread pid is %d", gettid());
    // RCLCPP_INFO(this->get_logger(), "timer2 sleep for 5s...");
    // rclcpp::sleep_for(3s);
    RCLCPP_INFO(this->get_logger(), "Timer 2 callback");
  }

private:
  rclcpp::TimerBase::SharedPtr timer1_;
  rclcpp::TimerBase::SharedPtr timer2_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<MultiTimerNode>("multi_timer_node");
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}
